package com.tonyodev.fetch2.database;

import ohos.utils.Pair;

import com.tonyodev.fetch2.PrioritySort;
import com.tonyodev.fetch2.Status;
import com.tonyodev.fetch2core.Extras;
import com.tonyodev.fetch2core.Logger;

import java.io.Closeable;
import java.util.List;

/**
 * @since 2021-05-24
 */
public interface FetchDatabaseManager extends Closeable {

    boolean isClosed();

    void setClosed(boolean isClosed);

    Logger getLogger();

    void setLogger(Logger logger);

    Delegate getDelegate();

    void setDelegate(Delegate delegate);

    Pair<DownloadInfo, Boolean> insert(DownloadInfo downloadInfo);

    List<Pair<DownloadInfo, Boolean>> insert(List<DownloadInfo> downloadInfoList);

    void delete(DownloadInfo downloadInfo);

    void delete(List<DownloadInfo> downloadInfoList);

    void deleteAll();

    void update(DownloadInfo downloadInfo);

    void update(List<DownloadInfo> downloadInfoList);

    void updateFileBytesInfoAndStatusOnly(DownloadInfo downloadInfo);

    List<DownloadInfo> get();

    DownloadInfo get(int id);

    List<DownloadInfo> get(List<Integer> ids);

    DownloadInfo getByFile(String file);

    List<DownloadInfo> getByStatus(Status status);

    List<DownloadInfo> getByStatus(List<Status> statuses);

    List<DownloadInfo> getByGroup(int group);

    List<DownloadInfo> getDownloadsInGroupWithStatus(int groupId, List<Status> statuses);

    List<DownloadInfo> getDownloadsByRequestIdentifier(long identifier);

    List<DownloadInfo> getDownloadsByTag(String tag);

    List<Integer> getAllGroupIds();

    List<DownloadInfo> getPendingDownloadsSorted(PrioritySort prioritySort);

    void sanitizeOnFirstEntry();

    DownloadInfo updateExtras(int id, Extras extras);

    long getPendingCount(boolean includeAddedDownloads);

    DownloadInfo getNewDownloadInfoInstance();

    interface Delegate {

        void deleteTempFilesForDownload(DownloadInfo downloadInfo);

    }

}
